%
% \iffalse
%
% scrtime.dtx Copyright (C) 1994 Markus Kohm
%
% This file is part of the LaTeX2e KOMA-Script-Bundle
%
% It should be distributed UNCHANGED and together with all other
% files in the KOMA-Script-Bundle. The file readme.txt contains a list
% of all these files.
%
% A modified version of this file may be distributed, but it should
% be distributed with a DIFFERENT name. Changed files must be
% distributed TOGETHER WITH A COMPLETE AND UNCHANGED distribution
% of these files.
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%<*dtx>
            \ProvidesFile{scrtime.dtx}
%</dtx>
%<scrtime|scrdate>\NeedsTeXFormat{LaTeX2e}[1994/06/01]
%<driver>   \ProvidesFile{scrtime.drv}
%<scrtime>\ProvidesPackage{scrtime}
%<scrdate>\ProvidesPackage{scrdate}
                [1994/12/31 v1.0a LaTeX2e KOMA
%<scrtime|scrdate>                 package]
%<*driver>
                 driver]
\documentclass{ltxdoc}
\usepackage[a4paper]{typearea}
\begin{document}
 \DocInput{scrtime.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{249}
% \GetFileInfo{scrtime.dtx}
% \title{The \textsf{KOMA}-timedate-bundle\thanks{This file has
%        version number \fileversion, last revised \filedate.}}
% \author{Markus Kohm}
% \date{\filedate}
% \maketitle
%
% \def\oarg#1{{\ttfamily[}{\em#1\/}{\ttfamily]}}
% \def\arg#1{{\ttfamily\char`\{}{\em#1\/}{\ttfamily\char`\}}}
% \def\star{{\ttfamily*}}
% \makeatletter
% \def\Describe@Macro#1{\endgroup
%              \setbox0=\lastbox\llap{\PrintDescribeMacro{#1}}}%
% \def\Describe@Env#1{\endgroup
%              \setbox0=\lastbox\llap{\PrintDescribeEnv{#1}}}%
% \makeatother
% \marginparsep0pt
%
% \begin{abstract}
% This bundle includes a package \texttt{scrtime} defining some
% macros to handle compilation-time.
% It's a very simple implementation similar to \texttt{time.sty}.
% I've tried to use no additional register.
%
% The second package \texttt{scrdate} defines some macros to
% handle the name of the day!
% \end{abstract}
%
% \tableofcontents
%
% \section{Introduction}
% \subsection{\texttt{scrtime}-package}
% \DescribeMacro
% \today\\
% \DescribeMacro
% \date\arg{today's-value}\\
% \DescribeMacro
% \thistime\oarg{hourseparator}\\
% \DescribeMacro
% \settime\arg{thistime's-value}\\
% At \LaTeX\ there's a macro |\today| to get compilation-date. There's
% a macro |\date| to set the value of |\today|, too. But to handle
% compilation-time there ist only a macro |\time| which shows the
% gone minutes of the day.
%
% With the macro |\thistime| you get the actual time. The optional
% argument \oarg{hourseparator} is used to separate hours and minutes.
% Default-value ist ``|:|''.
%
% With the macro |\settime| you may set the value of |\thistime|. After
% this the optional argument of |\thistime| will be ignored.
%
%
% \subsection{\texttt{scrdate}-package}
%
% At \LaTeX\ there are macros to get the actual day or month or year. Using
% |\today| you even may get the name of the month, but you will never get the
% name of the day.
%
% This package defines some macros to handle the name of the day.
%
% \begin{description}
% \item[Important:] If you use language-packages like \texttt{german} or
% \texttt{babel}, these \emph{must} be loaded \emph{after}
% \texttt{scrdate}-package. Otherwise the name of the day'll be wrong!
% \end{description}
%
% \noindent\texttt{scrdate} knows four languages:
% \begin{itemize}
% \item english
% \item USenglish
% \item german
% \item french
% \end{itemize}
%
% You may add additional languages using the configurationfile
% \texttt{scrdate.cfg}. There you have to define a macro
% |\dayname@|\emph{language}. This macro has to be something like this:
% \begin{flushleft}\noindent%
% |\newcommand\dayname@|\emph{language}|[1]{%|\\
% | \begingroup%|\\
% |  \@tempcnta #1%|\\
% |  \ifcase\@tempcnta%|\\
% |    |\emph{Monday}|\or |\emph{Tuesday}|\or |\emph{Wednesday}|\or%|\\
% |    |\emph{Thursday}|\or |\emph{Friday}|\or |\emph{Saturday}|\or%|\\
% |    |\emph{Sunday}|\fi\endgroup%|\\
% |}|
% \end{flushleft}\par\noindent
% Also you have to redefine
% |\date|\emph{language} like this:
% \begin{flushleft}\noindent%
% \quad|\let\D@date|\emph{language}|=\date|\emph{language}\\
% \quad\quad|\def\date|\emph{language}%
%            |{\let\@dayname=\dayname@|\emph{language}%
%              |\D@date|\emph{language}|}%|
% \end{flushleft}\par
%
% \DescribeMacro
% \newdaylanguage\arg{language}\arg{Monday}\arg{Tuesday}\arg{Wednesday}%
% \arg{Thursday}\arg{Friday}\arg{Saturday}\arg{Sunday}\\
% defines the daynames of a language like shown before.
%
% \DescribeMacro
% \todaysname\\
% shows the name of the actual day (defined by |\year|, |\month| and
% |\day| or by |\dayname|).
%
% \DescribeMacro
% \dayname\arg{Name}\\
% sets the name of the day to \arg{Name}.
%
%
% \StopEventually
%
% \section{Implementation}
% \subsection{Time-macros}
%
%    \begin{macrocode}
%<*scrtime>
%    \end{macrocode}
%
% We use |\@tempcnta| and |\@tempcntb| but we know, that this is not
% a very good idea.
%
%  \begin{macro}{\thistime}
% First we have to calculate the hours and minutes. |\@tempcnta| are the
% hours and |\@tempcntb| are the minutes.
%    \begin{macrocode}
\def\thistime{\@ifnextchar[{\@thistime}{\@thistime[:]}}
\def\@thistime[#1]{%
  \begingroup
    \@tempcnta\time\divide\@tempcnta60\multiply\@tempcnta60%
    \@tempcntb\time\advance\@tempcntb-\@tempcntb%
    \divide\@tempcnta60%
%    \end{macrocode}
% Know we have to compose the value. If minutes less than 10
% there has to be an additional 0.
%    \begin{macrocode}
    \the\@tempcnta{#1}\ifnum\@tempcntb<10 0\fi\the\@tempcntb%
  \endgroup}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\settime}
% We simply have to set |\thistime|.
\newcommand\settime[1]{\renewcommand\thistime{#1}}
%  \end{macro}
%
%
% That's it:
%    \begin{macrocode}
%</scrtime>
%    \end{macrocode}
%
%
% \subsection{Date-macros}
%
%    \begin{macrocode}
%<*scrdate>
%    \end{macrocode}
%
% To handle them, we need counters. We use same as in \texttt{scrtime}.
%
%  \begin{macro}{\todaysname}
% This is not so easy. First we have to calculate how many days they are
% from 1st January 1980.
%    \begin{macrocode}
\newcommand\todaysname{%
  \begingroup%
  \@tempcnta\year\@tempcntb0%
  \ifnum\@tempcnta<1980 unknown\else%
    \advance\@tempcnta-1980%
    \@whilenum\@tempcnta>=4\do%
    {\advance\@tempcntb5\advance\@tempcnta-4}%
    \ifnum\@tempcnta>0%
      \ifnum\month>2\advance\@tempcntb1\fi%
    \else%
      \advance\@tempcntb\@tempcnta%
    fi%
    \ifcase\month\or\or\advance\@tempcntb3%  Jan =  28 + 3
                    \or\advance\@tempcntb3% +Feb =  56 + 3
                    \or\advance\@tempcntb6% +Mar =  84 + 6
                    \or\advance\@tempcntb1% +Apr = 119 + 1
                    \or\advance\@tempcntb4% +May = 147 + 4
                    \or\advance\@tempcntb6% +Jun = 175 + 6
                    \or\advance\@tempcntb2% +Jul = 210 + 2
                    \or\advance\@tempcntb5% +Aug = 238 + 5
                    \or%                    +Sep = 273 + 0
                    \or\advance\@tempcntb3% +Oct = 301 + 3
                    \or\advance\@tempcntb5% +Nov = 329 + 5
    \fi%
    \advance\@tempcntb\day%
    \advance\@tempcntb5% 0 is Monday!
    \@whilenum\@tempcntb>=7\do%
    {\advance\@tempcntb-7}%
%    \end{macrocode}
% Now we can say which day it is.
%    \begin{macrocode}
    \@dayname{\@tempcntb}%
  \fi\endgroup}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\nameday}
% We simply have to redefine |\todaysname|
%    \begin{macrocode}
\newcommand\nameday[1]{\renewcommand\todaysname{#1}}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\@dayname}
% This should be named selecting the language. So we do some changes
% at |\begin{document}| (and hope, |german.sty| or other will be
% loaded \emph{after} |scrdate|).
%    \begin{macrocode}
\AtBeginDocument{%
  \let\D@dategerman=\dategerman%
    \def\dategerman{\let\@dayname=\dayname@german\D@dategerman}%
  \let\D@dateenglish=\dateenglish%
    \def\dateenglish{\let\@dayname=\dayname@english\D@dateenglish}%
  \let\D@dateUSenglish=\dateUSenglish%
    \def\dateUSenglish{\let\@dayname=\dayname@english\D@dateUSenglish}%
  \let\D@datefrench=\datefrench%
    \def\datefrench{\let\@dayname=\dayname@french\D@datefrench}
  \ifcase\language
    \dateUSenglish
  \or
    \dategerman
  \or
    \datefrench
  \fi
}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\dayname@german}
% And here are the german daynames.
%    \begin{macrocode}
\newcommand\dayname@german[1]{%
  \begingroup%
  \@tempcnta #1%
  \ifcase\@tempcnta%
    Montag\or Dienstag\or Mittwoch\or Donnerstag\or%
    Freitag\or Samstag\or Sonntag\fi\endgroup%
}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\dayname@english}
% And the english daynames
%    \begin{macrocode}
\newcommand\dayname@english[1]{%
  \begingroup%
  \@tempcnta #1%
  \ifcase\@tempcnta%
    Monday\or Tuesday\or Wednesday\or Thursday\or%
    Friday\or Saturday\or Sunday\fi\endgroup%
}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\dayname@french}
% And the french daynames
%    \begin{macrocode}
\newcommand\dayname@french[1]{%
  \begingroup%
  \@tempcnta #1%
  \ifcase\@tempcnta%
    Lundi\or Mardi\or Mercredi\or Jeudi\or%
    Vendredi\or Samedi\or Dimanche\fi\endgroup%
}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\newdaylanguage}
% We only have to define like before.
%    \begin{macrocode}
\newcommand\newdaylanguage[8]{%
%    \end{macrocode}
% First we define the new macro |\dayname@|\emph{language}:
%    \begin{macrocode}
  \expandafter\def\csname dayname@#1\endcsname{%
    \begingroup%
      \@tempcnta #1%
      \ifcase\@tempcnta%
        #2\or #3\or #4\or #5\or #6\or #7\or #8\fi\endgroup%
  }
%    \end{macrocode}
% Then we define, what to do at |\begin{document}|:
%    \begin{macrocode}
  \AtBeginDocument{
%    \end{macrocode}
% There we first save |\date|\emph{language} as |\D@date|\emph{language}:
%    \begin{macrocode}
    \expandafter\let\csname D@date#1\endcsname=\csname date#1\endcsname
%    \end{macrocode}
% Now we redefine |\date|\emph{language}. It first defines |\@dayname| and
% then calls saved macro.
%    \begin{macrocode}
    \expandafter\def\csname date#1\endcsname{%
      \let\@dayname=\csname dayname@#1\endcsname\csname D@date#1\endcsname}%
%    \end{macrocode}
% Last we have to select this new |\date|\emph{language}, if the actual
% language is the new language. We do this using the
% \texttt{german.sty}-language-selection with |\l@|\emph{language}:
%    \begin{macrocode}
    \expandafter\ifx\csname l@#1\endcsname\relax
    \else
      \ifnum\language=\csname l@#1\endcsname
        \csname date#1\endcsname
      \fi
    \fi
  }
}
%    \end{macrocode}
%  \end{macro}
%
% Last but not least file \texttt{scrdate.cfg} has to be included, if it exists.
%    \begin{macrocode}
\InputIfFileExists{scrdate.cfg}
           {\typeout{*************************************^^J%
                     * Local config file scrdate.cfg used^^J%
                     *************************************}}
           {}
%    \end{macrocode}
%
% That's it:
%    \begin{macrocode}
%</scrdate>
%    \end{macrocode}
%
%
% \Finale
%
\endinput